/**
 * 
 */
package com.fw.timesheet.dao;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * @author sigit <br>
 * @version 1.0 <br>
 * Application : Alarm Reduction <br>
 * Copyright (c) fastwire-group 2011 <br>
 * <br>
 */
public class BaseDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(BaseDAO.class);

	public void saveOrUpdate(Object transientInstance) {
		StringBuffer sb = new StringBuffer("Saving ");
		try	{
			sb.append(transientInstance.getClass().getSimpleName());
		} catch (Exception e) {
			log.debug("@Timesheet>Error trying to get BusinessObject name.", e);
			sb.append("businessObject");
		}
		sb.append(" instance.");
		log.debug(sb.toString());
		try {
			Object object = getHibernateTemplate().merge(transientInstance);
			getHibernateTemplate().saveOrUpdate(object);
			
			System.out.println("YTest ==");
			log.debug("@Timesheet>save successful");
		} catch (RuntimeException re) {
			log.error("@Timesheet>save failed", re);
			throw re;
		}
	}
	
	public void clearSession() {
		log.debug("@Timesheet>clearing the session");
		try {
		   getHibernateTemplate().clear();
		   log.debug("@Timesheet>clearing the session successful");
		} catch (RuntimeException re) {
			log.error("@Timesheet>clearing the session failed", re);
			throw re;
		}
	}
	
	public void flushTransaction() {
		log.debug("@Timesheet>flushing the transaction");
		try {
		   getHibernateTemplate().flush();
		   log.debug("@Timesheet>flushing the transaction successful");
		} catch (RuntimeException re) {
			log.error("@Timesheet>flushing the transaction failed", re);
			throw re;
		}

	}
}
